package com.ysactive.config;

import java.util.Arrays;

/**
 * @Auther: pl
 * @Date: 2020/9/20 21:48
 * @Description: 此枚举作为常量使用，为防止属性被修改，枚举中属性必须私有且不可改变，不能提供set方法
 */
public enum ErrorCodeEnume {
    /**
     * 系统未知异常
     */
    UNKNOW_EXCEPTION("999", "ERROR"),
    /**
     * 成功
     */
    SUCCESS("000", "参数格式校验失败"),
    /**
     * 用户冻结 01中文 02英文 03巴西 04墨西哥
     */
    LOGIN_ERROR_01("001", "用户名或密码错误"),
    LOGIN_ERROR_02("001", "Incorrect username or password"),
    LOGIN_ERROR_03("001", "Incorrect username or password"),
    LOGIN_ERROR_04("001", "Incorrect username or password"),

    EMAIL_ERROR1_01("001", "已发送过邮箱注册验证码"),
    EMAIL_ERROR2_02("001", "Incorrect username or password"),
    EMAIL_ERROR3_03("001", "Incorrect username or password"),
    EMAIL_ERROR4_04("001", "Incorrect username or password"),

    EMAIL_ERROR5_01("001", "请输入正确的验证码"),
    EMAIL_ERROR6_02("001", "Incorrect username or password"),
    EMAIL_ERROR7_03("001", "Incorrect username or password"),
    EMAIL_ERROR8_04("001", "Incorrect username or password"),


    TYPE_ERROR("99","类型必传")
    ;

    //错误码
    private final String code;
    //错误信息
    private final String msg;

    /**
     * 根据Key得到枚举的实例
     * Lambda表达式，比较判断（JDK 1.8）
     *
     * @param key
     * @return
     */
    public static ErrorCodeEnume getEnumType3(String key) {
        return Arrays.asList(ErrorCodeEnume.values()).stream()
                .filter(errorCodeEnume -> errorCodeEnume.code.equals(key))
                .findFirst().orElse(ErrorCodeEnume.UNKNOW_EXCEPTION);
    }


    ErrorCodeEnume(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

}
